// src/services/adminService.js
import http from '../utils/http'

export default {
    // 用户管理相关API
    async getUsers(uid = null) {
        try {
            const url = uid ? `/admin/queryUser/${uid}` : '/admin/queryUser/0'
            const response = await http.get(url)
            return response
        } catch (error) {
            console.error('获取用户列表失败:', error)
            throw error
        }
    },

    async banUser(uid, aid) {
        try {
            await http.put('/admin/banUser', null, {
                params: { uid, aid }
            })
        } catch (error) {
            console.error('封禁用户失败:', error)
            throw error
        }
    },

    async unbanUser(uid, aid) {
        try {
            await http.put('/admin/banUser', null, {
                params: { uid, aid, status: 1 }
            })
        } catch (error) {
            console.error('解封用户失败:', error)
            throw error
        }
    },

    // 博客管理相关API
    async getBlogs(ctid = null) {
        try {
            const url = ctid ? `/admin/queryBlog/${ctid}` : '/admin/queryBlog/0'
            const response = await http.get(url)
            return response
        } catch (error) {
            console.error('获取博客列表失败:', error)
            throw error
        }
    },

    async approveBlog(ctid) {
        try {
            await http.put(`/admin/goContent/${ctid}`)
        } catch (error) {
            console.error('审核通过失败:', error)
            throw error
        }
    },

    async rejectBlog(ctid, reason) {
        try {
            await http.post('/admin/reviewBlog', {
                ctid,
                reason
            })
        } catch (error) {
            console.error('驳回博客失败:', error)
            throw error
        }
    },

    // 活动管理相关API
    async publishActivity(activity) {
        try {
            await http.post('/admin/publishActivity', activity)
        } catch (error) {
            console.error('发布活动失败:', error)
            throw error
        }
    },

    // 分区管理相关API
    async addPartition(partition) {
        try {
            await http.post('/admin/addPartition', partition)
        } catch (error) {
            console.error('添加分区失败:', error)
            throw error
        }
    },

    // 反馈管理相关API
    async getFeedbacks() {
        try {
            const response = await http.get('/admin/getFeedback')
            return response
        } catch (error) {
            console.error('获取反馈列表失败:', error)
            throw error
        }
    }
}